package com.edu.study.base.stuQuestionOption.controller;

import com.edu.study.base.stuQuestionOption.domain.StuQuestionOption;
import com.edu.study.base.stuQuestionOption.service.IStuQuestionOptionService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.UUIDUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * 试题选项内容Controller
 *
 * @author jjt
 * @date 2021-04-02
 */
@RestController
@RequestMapping("/questionOption/option")
public class StuQuestionOptionController extends BaseController
{
    @Autowired
    private IStuQuestionOptionService stuQuestionOptionService;

    /**
     * 查询试题选项内容列表
     */
    @PreAuthorize("@ss.hasPermi('questionOption:option:list')")
    @GetMapping("/list")
    public TableDataInfo list(StuQuestionOption stuQuestionOption)
    {
        startPage();
        List<StuQuestionOption> list = stuQuestionOptionService.selectStuQuestionOptionList(stuQuestionOption);
        return getDataTable(list);
    }

    /**
     * 导出试题选项内容列表
     */
    @PreAuthorize("@ss.hasPermi('questionOption:option:export')")
    @Log(title = "试题选项内容", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(StuQuestionOption stuQuestionOption)
    {
        List<StuQuestionOption> list = stuQuestionOptionService.selectStuQuestionOptionList(stuQuestionOption);
        ExcelUtil<StuQuestionOption> util = new ExcelUtil<StuQuestionOption>(StuQuestionOption.class);
        return util.exportExcel(list, "option");
    }

    /**
     * 获取试题选项内容详细信息
     */
    @PreAuthorize("@ss.hasPermi('questionOption:option:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(stuQuestionOptionService.selectStuQuestionOptionById(id));
    }

    /**
     * 新增试题选项内容
     */
    @PreAuthorize("@ss.hasPermi('questionOption:option:add')")
    @Log(title = "试题选项内容", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StuQuestionOption stuQuestionOption)
    {

//        stuQuestionOption.setId(UUIDUtils.getUUID());
        stuQuestionOption.setCreateDate(new Date());
        stuQuestionOption.setCreateBy(SecurityUtils.getUserId().toString());
        stuQuestionOption.setDelFlag("0");
        return toAjax(stuQuestionOptionService.insertStuQuestionOption(stuQuestionOption));
    }

    /**
     * 修改试题选项内容
     */
    @PreAuthorize("@ss.hasPermi('questionOption:option:edit')")
    @Log(title = "试题选项内容", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StuQuestionOption stuQuestionOption)
    {
        return toAjax(stuQuestionOptionService.updateStuQuestionOption(stuQuestionOption));
    }

    /**
     * 删除试题选项内容
     */
    @PreAuthorize("@ss.hasPermi('questionOption:option:remove')")
    @Log(title = "试题选项内容", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(stuQuestionOptionService.deleteStuQuestionOptionByIds(ids));
    }
}
